import {Component, OnInit} from '@angular/core';
import {DeviceService} from "./device-component.service";
import {Device} from '../model/Device';

@Component({
  selector: 'app-device-component',
  templateUrl: './device-component.component.html',
  styleUrls: ['./device-component.component.scss'],
  providers: [DeviceService]
})
export class DeviceComponentComponent implements OnInit {
  private devices: Device[] = [];

  constructor(private deviceService: DeviceService) {
  }

  ngOnInit() {
    this.deviceService.list().subscribe(ds => this.devices = ds, e => {
      console.log(e)
    });
  }

  doDelete(device: Device) {
    let id = device.id;
    this.deviceService.delete(id).subscribe(data => {
      this.devices.splice(this.devices.findIndex(v => v.id === id), 1);
    });
  }

}
